const cloud = require('wx-server-sdk')
// 初始化云开发
cloud.init({
  env: 'liucheng-2gmqvcgs50e86304' // 使用指定的云环境
});
const db = cloud.database()
const _ = db.command

exports.main = async (event, context) => {
  const { startOfWeek, endOfWeek, today } = event

  // 查询超时订单
  const overdueOrders = await db.collection('Order')
    .where({
      expectDeliTime: _.lt(today)
    })
    .get()

  // 查询本周订单
  const weeklyOrders = await db.collection('Order')
    .where({
      expectDeliTime: _.gte(startOfWeek).and(_.lte(endOfWeek))
    })
    .get()

  return {
    overdueOrders: overdueOrders.data,
    weeklyOrders: weeklyOrders.data
  }
}
